#include <stdio.h>
#include <stdint.h>

#define FIFORANGE 6

typedef struct basic {
    uint8_t ub_id;
    uint8_t ub_age;
}st_basic_t;

typedef struct student {
    st_basic_t st_basicinfo[5];
    uint8_t ub_length;
}st_student_packet_t;

typedef struct {
    st_student_packet_t arr[FIFORANGE];
    st_student_packet_t* head;
    st_student_packet_t* tail;
}object_t;

uint8_t entry(object_t* object, st_student_packet_t data);
uint8_t delete(object_t* object);
void display(object_t* object);

int main(void)
{
    object_t object = {
        .arr = 0,
        .head = object.arr,
        .tail = object.arr
    };
    //填包0
    object.arr[0].st_basicinfo[0] = (st_basic_t){
        .ub_id = 0,
        .ub_age = 12,
    };
    object.arr[0].st_basicinfo[1] = (st_basic_t){
        .ub_id = 1,
        .ub_age = 13,
    };
    object.arr[0].st_basicinfo[2] = (st_basic_t){
        .ub_id = 2,
        .ub_age = 14,
    };
    object.arr[0].ub_length = sizeof(st_basic_t);

    //填包1
    object.arr[1].st_basicinfo[0] = (st_basic_t){
        .ub_id = 0,
        .ub_age = 15,
    };
    object.arr[1].st_basicinfo[1] = (st_basic_t){
        .ub_id = 1,
        .ub_age = 16,
    };
    object.arr[1].st_basicinfo[2] = (st_basic_t){
        .ub_id = 2,
        .ub_age = 17,
    };
    object.arr[1].ub_length = sizeof(st_basic_t);

        //填包2
    object.arr[2].st_basicinfo[0] = (st_basic_t){
        .ub_id = 0,
        .ub_age = 18,
    };
        object.arr[2].st_basicinfo[1] = (st_basic_t){
        .ub_id = 1,
        .ub_age = 19,
    };
        object.arr[2].st_basicinfo[2] = (st_basic_t){
        .ub_id = 2,
        .ub_age = 20,
    };
        object.arr[2].ub_length = sizeof(st_basic_t);

    if (entry(&object, object.arr[0]) == 1) {
        printf("entry win\n");
    }
    else {
        printf("entry false\n");
    }

    if (entry(&object, object.arr[1]) == 1) {
        printf("entry win\n");
    }
    else {
        printf("entry false\n");
    }
    if (entry(&object, object.arr[2]) == 1) {
       printf("entry win\n");
    }
 
    display(&object);

    delete(&object);
    puts("");
    display(&object);

    delete(&object);
    puts("");
    display(&object);

}

uint8_t entry(object_t* object, st_student_packet_t data)
{
    if (object->tail > &object->arr[FIFORANGE - 1])
    {
        printf("queue is full 满了\n");
    }
    else
    {
        *(object->tail) = data;
        object->tail++;
    }


    return 1;
}

uint8_t delete(object_t* object)
{
    if (object->head != object->tail)
    {
        object->head++;
    }
    else {
        puts("object is nothing  空了");
    }

    return 1;
}

void display(object_t* object)
{
    st_student_packet_t* temp = object->head;
    uint8_t i = 0;
    uint8_t j = 0;

    while (temp != object->tail)
    {
      //  printf("%d\t", *temp);
        for (j = 0; j < 3; j++) {
            printf("packet[%d].st_basicinfo[%d]:  \n", i, j);
            printf("id:%d    age:%d\n", temp->st_basicinfo[j].ub_id, temp->st_basicinfo[j].ub_age);
        }
        i++;
        temp++;
        puts("");
    }


}